package org.jeecg.modules.flow.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.flow.entity.ActHiProcessInstance;
import org.jeecg.modules.flow.query.HistoryInstanceQuery;
import org.jeecg.modules.flow.service.IActHiProcessInstanceService;
import org.jeecg.modules.flow.vo.HistoryProcessInstanceVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @Description: actProcessInstance
 * @Author: jeecg-boot
 * @Date: 2021-12-29
 * @Version: V1.0
 */
@Api(tags = "历史流程实例API")
@RestController
@RequestMapping("/flow/actHiProcessInstance")
@Slf4j
public class ActHiProcessInstanceController extends JeecgController<ActHiProcessInstance, IActHiProcessInstanceService> {
    @Autowired
    private IActHiProcessInstanceService actProcessInstanceService;

    /**
     * 分页列表查询
     *
     * @param actHiProcessInstance
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @ApiOperation(value = "分页列表查询", notes = "actHiProcessInstance-分页列表查询")
    @GetMapping(value = "/list")
    public Result<?> queryPageList(ActHiProcessInstance actHiProcessInstance,
                                   @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                   @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                   HttpServletRequest req) {
        QueryWrapper<ActHiProcessInstance> queryWrapper = QueryGenerator.initQueryWrapper(actHiProcessInstance, req.getParameterMap());
        Page<ActHiProcessInstance> page = new Page<ActHiProcessInstance>(pageNo, pageSize);
        IPage<ActHiProcessInstance> pageList = actProcessInstanceService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

    @ApiOperation(value = "查询历史流程实例列表", notes = "actHiProcessInstance-分页查询历史流程实例列表")
    @GetMapping(value = "/queryHistoricProcessInstances")
    public Result<Page<HistoryProcessInstanceVo>> queryHistoricProcessInstances(HistoryInstanceQuery query
            , @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo
            , @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        Page<HistoryProcessInstanceVo> page = actProcessInstanceService.queryHistoricProcessInstances(query, pageNo, pageSize);
        return Result.OK(page);
    }


}
